<?php
class advCategoryModel extends Model{
	private $tbl = 'advertise_category';
	private $rule = array(
			'name'=>array('required'=>true,'min'=>1,'max'=>15),
			);

	public function __construct(){
		parent::__construct($this->tbl);
	}

	public function add($data){
		if( $this->rule && !$this->valid($data, $this->rule) ) return false;
		return $this->value($data)->insert();
	}

	public function edit($id, $data){
		if( empty($id) || !is_int($id) ) return false;
		if( !$this->valid($data, $this->rule) ) return false;
		return $this->where("id=$id")->value($data)->update();
	}

	public function del($id){
		$id = intval($id);
		if( !is_int($id) || $id<0 ) return false;
		return $this->where("id=$id")->delete();
	}

	public function get_categories($where=""){
		$arr = $this->where($where)->order('id DESC')->get();
		return $arr;
	}
}
